﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="fileManager.ascx.cs" Inherits="adm_vlg_resources_WebUserControl" %>
<%--JAVASCRIPT + CSS--%>
<link href="<%=BasePath %>resources/jqueryFileTree/jqueryFileTree.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="../../resources/uploadify/swfobject.js"></script>
<script type="text/javascript" src="../../resources/uploadify/jquery.uploadify.v2.1.4.min.js"></script>

<%--===========================================--%>

<script type="text/javascript">
    $("#content").height($(window).height() - 160);
    $(document).ready(function () {
        $(".list_resource").height($(window).height() - 290);

        rootPath = '<%=BasePath %>';
        pathUpload = '/Uploads/';
        scriptPath = rootPath + 'resources/resourceAjax.ashx';
        var new_win = '<%=new_win %>';
        var edMCE = '<%=edMCE %>';

        //LOAD THU MUC O~ DAY
        function LoadResource(_path) {
            $("#list_resource_contain").hide();
            $.post(scriptPath, { dir: _path }, function (data) {
                $("#list_resource_contain").html(data);
                $("#list_resource_contain").fadeIn(200);

                $(".file_top").click(function () {
                    if ($(this).parent().hasClass('directory')) {
                        LoadResource($(this).attr('rel'));
                    }
                });

                $(".file_top").dblclick(function () {
                    if ($(this).parent().hasClass('directory')) {

                    }
                    else {
                        if (new_win == "1") {
                            FileBrowserDialogue.mySubmit(encodeURI($(this).attr('rel')).replace('#', '%23'));
                        }
                        else
                            if (new_win == "2") {
                                parent.InsertImgToMCE(encodeURI($(this).attr('rel')).replace('#', '%23'), edMCE);
                            }
                            else {
                                parent.SetUrl(encodeURI($(this).attr('rel')).replace('#', '%23'), '<%=param %>');
                            }
                    }
                });

                $(".xoa_thumuc").click(function () {
                    var answer = confirm('Bạn muốn xóa thư mục này!');
                    if (answer)
                        $.post(scriptPath, { link: $(this).attr('rel'), act: "delete_dir" }, function (data) {
                            LoadResource(_path);
                        });
                });

                $(".xoa_taptin").click(function () {
                    var answer = confirm('Bạn muốn xóa tập tin này!');
                    if (answer)
                        $.post(scriptPath, { link: $(this).attr('rel'), act: "delete_file" }, function (data) {
                            LoadResource(_path);
                        });
                });

                $('#file_upload').uploadifySettings('folder', _path);
                pathUpload = _path;

                $(".txtPath").html(_path);
            });
        }

        LoadResource(pathUpload);
        $(".txtPath").html(pathUpload);

        //UPLOAD
        $('#file_upload').uploadify({
            'uploader': rootPath + 'resources/uploadify/uploadify.swf',
            'script': rootPath + 'resources/uploadify/uploadify.ashx',
            'cancelImg': rootPath + 'resources/uploadify/cancel.png',
            'folder': pathUpload,
            'auto': true,
            'multi': true,
            'onAllComplete': function (event, data) {
                //alert(data)   
                LoadResource(pathUpload);
            }
        });

        $("#butt_new_folder").click(function () {
            txtName = $("#txtNewDir").val();
            if (txtName == "" || txtName == " ")
                alert("Mời bạn nhập tên thư mục!");
            else
                $.post(scriptPath, { dir: pathUpload + txtName, act: "new_dir" }, function (data) {
                    LoadResource(pathUpload);
                    $("#txtNewDir").val("")
                });
        });
    });
</script>
<table style="width:100%;" class="adminlist">
    <tr>
        <td style="background:#f0f0f0">
            <%--<a id="butt_insert" class="link_tool insert_tool" href="#">Chèn</a>--%>
            <%--<a id="butt_delete" class="link_tool delete_tool" href="#">Xóa</a>--%>
        <div class="txtPath"></div>    
        </td>
        <td style="background:#f0f0f0" align=right>
            <input id="txtNewDir" type="text" style="width:200px"/>
            <a id="butt_new_folder" class="link_tool new_folder_tool" href="#">Tạo thư mục</a></td>
        <td style="background:#f0f0f0; font-weight:bold;">
            UPLOAD HÌNH ẢNH</td>
    </tr>
    <tr>
        <td valign="top" width="455" colspan="2">
        <asp:Panel ID="Panel2" runat="server" CssClass="list_resource" ScrollBars="Vertical">
        <div id="list_resource_contain"></div>
        </asp:Panel>
        </td>        
        <td valign="top"><div class="upload_box"><input id="file_upload" type="file" name="file_upload" /></div></td>       
    </tr>
    <tr>
        <td valign="top" colspan="2" style="background:#f0f0f0"></td>        
        <td valign="top" style="background:#f0f0f0">&nbsp;</td>       
    </tr>
</table>

<script src="../adm_vlg/js/tiny_mce/tiny_mce_popup.js" type="text/javascript"></script>
<script type="text/javascript">
    var FileBrowserDialogue = {
        init: function () {
            // Here goes your code for setting your custom things onLoad.
        },
        mySubmit: function (url) {
            var win = tinyMCEPopup.getWindowArg("window");

            // insert information now
            win.document.getElementById(tinyMCEPopup.getWindowArg("input")).value = url;

            // are we an image browser
            if (typeof (win.ImageDialog) != "undefined") {
                // we are, so update image dimensions...
                if (win.ImageDialog.getImageData)
                    win.ImageDialog.getImageData();

                // ... and preview if necessary
                if (win.ImageDialog.showPreviewImage)
                    win.ImageDialog.showPreviewImage(URL);
            }

            // close popup window
            tinyMCEPopup.close();
        }
    }

    tinyMCEPopup.onInit.add(FileBrowserDialogue.init, FileBrowserDialogue);
</script>